﻿using ControllerClient.Bean;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ControllerClient.Tools
{
     public static  class ScheduleTools
    {
         public static Schedule getSchedule(string cmdfilename)
         {
             Schedule Schedule = new Schedule();
             TxtReader tr = new TxtReader(cmdfilename);
             string[] cmdstrs = tr.readUTF8();
             if (cmdstrs == null || cmdstrs.Length==0)
             {
                 return null;
             }
             for (int i = 0; i < cmdstrs.Length; i++)
             {
                 LogHelper.Debug(cmdstrs[i], Schedule.GetType());
             }
             Schedule.Cmdnum = cmdstrs[0].Replace("[01]", "|").Replace("[03]", "|").Replace("[05]", "|").Replace("[07]", "|").Split('|')[2];
             Schedule.IsScannum = cmdstrs[1].Replace("[01]", "|").Replace("[03]", "|").Replace("[05]", "|").Replace("[07]", "|").Split('|')[2];
             Schedule.NotScannum = cmdstrs[2].Replace("[01]", "|").Replace("[03]", "|").Replace("[05]", "|").Replace("[07]", "|").Split('|')[2];
            Schedule.TotalEpc = cmdstrs[3].Replace("[01]", "|").Replace("[03]", "|").Replace("[05]", "|").Replace("[07]", "|").Split('|')[2];
            Schedule.ScanEpc = cmdstrs[4].Replace("[01]", "|").Replace("[03]", "|").Replace("[05]", "|").Replace("[07]", "|").Split('|')[2];
            Schedule.SurplusEpc = cmdstrs[5].Replace("[01]", "|").Replace("[03]", "|").Replace("[05]", "|").Replace("[07]", "|").Split('|')[2];

            if (cmdstrs.Length ==7)
             {
                if (cmdstrs[6].Length > 0)
                {
                    string[] epcs = cmdstrs[6].Split('|');
                    
                    Schedule.EpcList = epcs;
                    LogHelper.Debug("任务总金额:" + Schedule.Cmdnum, Schedule.GetType());
                    LogHelper.Debug("已扫金额:" + Schedule.IsScannum, Schedule.GetType());
                    LogHelper.Debug("剩余金额:" + Schedule.NotScannum, Schedule.GetType());
                    LogHelper.Debug("任务" + Schedule.TotalEpc + "个包");
                    LogHelper.Debug("目前读到" + Schedule.ScanEpc + "个包");
                    LogHelper.Debug("剩余读到" + Schedule.SurplusEpc + "个包");
                    //for (int i = 0; i < epcs.Length-1; i++)
                    //{
                    //    LogHelper.Debug("epc" + i + "=" + Schedule.EpcList[i]);
                    //    TagEpcData ted = EpcReader.readEpc(StringAndBytesHelper.strToToHexByte(Schedule.EpcList[i]));
                    //    LogHelper.Debug("包号:" + ted.Tagid.ToString().PadLeft(10, '0'));
                    //    LogHelper.Debug("券别:" + PervalueHelper.getPervalue(ted.Pervalueid));
                    //}
                }
                
             }
             
             return Schedule;
         }
    }
}
